<template>
    <LModalForm 
        :visible="visible"
        :confirmLoading="confirmLoading" 
        :title="title" 
        ref="entityFieldForm" 
        :formAttributes="formAttributes" 
        @handleOk="handleOk" 
        @handleCancel="handleCancel"
        @changeEventHandler="changeEventHandler"></LModalForm>

</template>

<script>
import LModalForm from "@/components/lt/form/LModalForm"
import request from '@/utils/request'
import pick from 'lodash.pick'

export default {
    name:'entityFieldForm',
    components:{
        LModalForm
    },
    data(){
        return{
            title:'详情',
            visible:false,
            confirmLoading: false,
            model:{},
            formAttributes:{
              type:'',//collapse,tabs
              formItems:[
                {
                  title:'标签一',
                  columns:1,
                  fields:[
                    {field:'entityClassName',label:'实体名称',component:'input',disabled:true,rules: [{ required: true, message: '不能为空!' }]},
                    {field:'entityField',label:'实体字段代码',component:'input',disabled:true,rules: [{ required: true, message: '不能为空!' }]},
                    {field:'dbField',label:'数据库字段',component:'input',disabled:true,rules: [{ required: true, message: '不能为空!' }]},
                    {field:'entityFieldTitle',label:'实体字段标题',component:'input',rules: [{ required: true, message: '不能为空!' }]},
                  ]
                },
              ]

            }


        }
    },
    methods:{
       
        edit (record) {
            this.visible = true
            this.model = Object.assign({}, record)
            this.$nextTick(() => {
               //自己业务
                this.$refs.entityFieldForm.getForm().setFieldsValue(pick(this.model,'entityClassName','entityField','dbField','entityFieldTitle'))
                
            })
        },
        handleOk(){
            const that = this;
            this.$refs.entityFieldForm.getForm().validateFields((err, values) => {
                if (!err) {
                   
                    that.confirmLoading = true
                    let formData = Object.assign(this.model, values);
                    request({url: '/SysEntityFieldController/save',method: 'post',data: formData}).then((res)=>{
                        if(res.success){
                            that.close()
                            that.$message.success(res.message);
                        }else{
                            that.$message.warning(res.message);
                        }
                    }).finally(() => {
                        that.confirmLoading = false;
                        
                    })
                    
                }
            })
        },
        handleCancel(){
            this.visible=false
        },
        close () {
            this.$emit('close');
            this.visible = false;
        },
        /**
         * 表单内容发生变化
         */
        changeEventHandler(changeItem){
           
           
        }
    },
    created(){
        
    },
}
</script>